package IA;

import iterators.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class CustomerQueue {

    private ArrayList<WaitingParty> customers;
    private ArrayList<Integer> waitingTimes;

    public CustomerQueue() {
        customers = new ArrayList<WaitingParty>();
        waitingTimes = new ArrayList<Integer>();
    }

    public Iterator<WaitingParty> getLongestFirstIterator() {
        return new LongestWaitingPartyItr(customers);
    }

    public Iterator<Integer> getPastWaitingTimeIterator() {
        return new ReverseIterator(waitingTimes);
    }
    
    public void addParty(int numCustomers, int EatTime) {
        customers.add(new WaitingParty(numCustomers, EatTime));
        SystemClock.getInstance().AddObserver(customers.get(customers.size() - 1));
    }

    public void CallParty(WaitingParty wp) {
        //remove party from clocks notify list
        SystemClock.getInstance().RemoveObserver(wp);
        waitingTimes.add(wp.getWaitingTime());
        //remove from  queue list
        customers.remove(wp);
    }

    public Integer getNumberOfCustomersWaiting() {
        return customers.size();
    }
    
    public List<WaitingParty> getList() {
        return Collections.unmodifiableList(customers);
    }
}
